from . import app_rendering
from flask import render_template, request
from conn_mysql import ConnectMysql



@app_rendering.route('/detail/<int:ID>')

def detail(ID):

    token = request.args.get('token')
    msg = request.args.get('msg')

    with ConnectMysql() as CM:
        #获取token值对应的companyID
        
        sql_token = "SELECT * FROM token WHERE token=%s"
        if token != None and token != "None":
            result_token = CM.select_one(sql_token, (token,))
            company_id = result_token['company_id']
        else:
            company_id = None

        
        sql = 'SELECT * FROM company WHERE id=%s'
        result_info = CM.select_one(sql, (ID,))
        print(result_info)
    
    return render_template('detail.html', msg = msg, 
                            result_info = result_info, 
                            token = token,
                            consumption_id = ID,
                            company_id = company_id
                            )



    